package com.zx.base.widget;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.text.Html;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

import com.zx.tradeclient.R;



public class ShowDialog {

	private String dialog_tile;
	private String dialog_yes;
	private String dialog_no;
	private String dialog_content;

	private Activity act;

	private boolean is_parent = false;

	public AlertDialog dlg;
	
	public Button bt_yes, bt_no;
	private LinearLayout showmain;
	private ImageView title_logo;

	public ShowDialog(Context context, String tile, String con, String yes,
			String no, boolean is_parent) {
		this.act = (Activity) context;
		dialog_tile = tile;
		dialog_yes = yes;
		dialog_no = no;
		dialog_content = con;
		this.is_parent = is_parent;
	}

	public void show() {
		if (is_parent) {
			dlg = new AlertDialog.Builder(act.getParent()).create();
		} else {
			dlg = new AlertDialog.Builder(act).create();
		}

		dlg.show();
		Window window = dlg.getWindow();
		// *** 主要就是在这里实现这种效果的.
		// 设置窗口的内容页面,shrew_exit_dialog.xml文件中定义view内容
		window.setContentView(R.layout.show_dialog);
		
		TextView tv_title = (TextView) window.findViewById(R.id.dialog_tile);
		tv_title.setText(dialog_tile);

		TextView tv_content = (TextView) window.findViewById(R.id.dialog_content);
		tv_content.setText(Html.fromHtml(dialog_content));
		title_logo=(ImageView)window.findViewById(R.id.dialog_tile_icon);
		bt_yes = (Button) window.findViewById(R.id.dialog_yes);
		bt_yes.setText(dialog_yes);
		/*bt_yes.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				
			}
		});*/
		showmain=(LinearLayout)window.findViewById(R.id.exitGameBackground);
		bt_no = (Button) window.findViewById(R.id.dialog_no);
		bt_no.setText(dialog_no);
		/*bt_no.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {

			}
		});*/
		if(dialog_tile.equals("")){
			tv_title.setVisibility(View.GONE);
			title_logo.setVisibility(View.GONE);
			showmain.setBackgroundResource(R.color.white);
		}
		if(dialog_yes.equals("")){
			bt_no.setLayoutParams(new LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
			bt_yes.setVisibility(View.GONE);
		}
		if(dialog_no.equals("")){
			bt_yes.setLayoutParams(new LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
			bt_no.setVisibility(View.GONE);
		}
		
	}

}
